package com.crr.mall.product.app;

import java.util.Arrays;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import cn.hutool.core.bean.BeanUtil;
import com.crr.mall.common.bean.ResultBean;
import com.crr.mall.common.utils.BaseController;
import com.crr.mall.product.query.BrandQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.crr.mall.product.entity.BrandEntity;
import com.crr.mall.product.service.BrandService;
import com.crr.mall.common.utils.PageUtils;
import com.crr.mall.common.utils.R;



/**
 * 品牌
 *
 * @author chenrenren
 * @email chenrenren@gmail.com
 * @date 2024-11-22 17:42:37
 */
@RestController
@RequestMapping("product/brand")
public class BrandController extends BaseController {
    @Autowired
    private BrandService brandService;

    /**
     * 列表
     */
    @PostMapping("/list")
   // @RequiresPermissions("product:brand:list")
    public ResultBean list(@RequestBody BrandQuery brandQuery){
        PageUtils pageUtils = brandService.queryByCondition(BeanUtil.beanToMap(brandQuery));
        return success("分页列表",pageUtils);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{brandId}")
   // @RequiresPermissions("product:brand:info")
    public R info(@PathVariable("brandId") Long brandId){
		BrandEntity brand = brandService.getById(brandId);

        return R.ok().put("brand", brand);
    }


    /**
     * 保存
     */
    @PostMapping ("/save")
   // @RequiresPermissions("product:brand:save")
    public ResultBean save(@Validated @RequestBody BrandEntity brand, BindingResult result){
     //   validate(result);
        boolean save = brandService.save(brand);
        return save?saveResult(1):saveResult(0);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
   // @RequiresPermissions("product:brand:update")
    public ResultBean update(@RequestBody BrandEntity brand){
        boolean b = brandService.updateById(brand);
        return b?updateResult(1):updateResult(0);
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
   // @RequiresPermissions("product:brand:delete")
    public R delete(@RequestBody Long[] brandIds){
		brandService.removeByIds(Arrays.asList(brandIds));

        return R.ok();
    }

}
